package service

import (
	"context"
	"gitee.com/shuokeyun/order-service/internal/domain"

	"google.golang.org/protobuf/types/known/wrapperspb"

	pb "gitee.com/shuokeyun/order-service/api/v1"
)

// OrderService .
type OrderService struct {
	pb.UnimplementedOrderServer
	order domain.OrderUsecase
}

// NewOrderServer .
func NewOrderServer(order domain.OrderUsecase) pb.OrderServer {
	return &OrderService{
		order: order,
	}
}

// CreateOrder 创建订单
func (s *OrderService) CreateOrder(ctx context.Context, req *pb.CreateOrderRequest) (*pb.CreateOrderReply, error) {
	do := createOrderRequestConvDo(req)
	do, err := s.order.CreateOrder(ctx, do)
	if err != nil {
		return nil, err
	}
	return &pb.CreateOrderReply{
		Id: do.Id,
	}, nil
}

// UpdateOrder 编辑订单
func (s *OrderService) UpdateOrder(ctx context.Context, req *pb.UpdateOrderRequest) (*wrapperspb.BoolValue, error) {
	return &wrapperspb.BoolValue{}, nil
}

// DeleteOrder 删除订单
func (s *OrderService) DeleteOrder(ctx context.Context, req *pb.DeleteOrderRequest) (*wrapperspb.BoolValue, error) {
	return &wrapperspb.BoolValue{}, nil
}

// GetOrder 获取单个订单
func (s *OrderService) GetOrder(ctx context.Context, req *pb.GetOrderRequest) (*pb.GetOrderReply, error) {
	order, err := s.order.GetOrder(ctx, req.GetId(), req.GetFieldMask().GetPaths())
	if err != nil {
		return nil, err
	}
	return orderConvOrderReply(order), nil
}

// ListOrder 获取订单列表
func (s *OrderService) ListOrder(ctx context.Context, req *pb.ListOrderRequest) (*pb.ListOrderReply, error) {
	return &pb.ListOrderReply{}, nil
}
